package com.huadao.cart_ccs.experiment.log.paramsAnysis;

import android.os.Bundle;

import com.github.mikephil.charting.data.Entry;
import com.huadao.cart_ccs.R;
import com.huadao.cart_ccs.common.UtilHelpers;
import com.huadao.cart_ccs.common.deviceController.CO2Controller;
import com.huadao.cart_ccs.greendao.GreenDaoManager;
import com.huadao.cart_ccs.greendao.entity.CO2;
import com.huadao.cart_ccs.greendao.gen.CO2Dao;

import java.util.List;

public class CO2Frag extends BaseEnvironmentFrag {

    private CO2Dao co2Dao;

    public static CO2Frag getInstance(int day) {
        Bundle bundle = new Bundle();
        bundle.putInt("day", day);
        CO2Frag co2Frag = new CO2Frag();
        co2Frag.setArguments(bundle);
        return co2Frag;
    }

    @Override
    protected void initView() {
        co2Dao = GreenDaoManager.getInstance().getNoCacheSession().getCO2Dao();
    }

    @Override
    protected float getLimitValue() {
//        return (float) ParamsPreferences.getInstance().getCO2();
        return (float) CO2Controller.getInstance().getSettedValue().floatValue();
    }

    @Override
    protected int getLimitLineColor() {
        return getResources().getColor(R.color.limit_line);
    }

    @Override
    protected String getLabel() {
        return getString(R.string.CO2);
    }

    @Override
    protected void setDataSet() {
        List<CO2> co2List = co2Dao.queryBuilder().where(CO2Dao.Properties.ProjectId.eq(projectId), CO2Dao.Properties.StageId.eq(stageId)).orderDesc(CO2Dao.Properties.Date).limit(8640).list();
        for (int i = co2List.size()-1; i >-1; i--) {
            CO2 co2 = co2List.get(i);
            float x = UtilHelpers.getTime(co2.getDate());
            Entry entry = new Entry(x, (float) co2.getCo2());
            lineData.addEntry(entry,0);
        }
    }

    @Override
    protected int getLineColor() {
        return getResources().getColor(R.color.CO2_line);
    }
}
